<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>安全图片查看器 - 密码保护</title>
    <!-- 引入OpenSeadragon库 -->
    <script src="js/openseadragon.min.js"></script>
    <script src="js/axios.min.js"></script>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css">
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
        }

        body {
            background: linear-gradient(135deg, #1a2a6c, #b21f1f, #fdbb2d);
            color: #fff;
            min-height: 100vh;
            display: flex;
            flex-direction: column;
            align-items: center;
            justify-content: center;
            padding: 20px;
        }

        .container {
            width: 100%;
            max-width: 1600px;
            display: flex;
            flex-direction: column;
            align-items: center;
        }

        label {
            font-weight: 500;
            font-size: 1.1rem;
        }

        /* 图片查看界面 */
        .viewer-interface {
            width: 100%;
            display: flex;
            flex-direction: column;
            gap: 20px;
        }

        header {
            text-align: center;
            padding: 20px;
            background: rgba(0, 0, 0, 0.3);
            border-radius: 15px;
            backdrop-filter: blur(10px);
            box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
        }

        h1 {
            font-size: 2.5rem;
            margin-bottom: 10px;
            text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
        }

        .viewer-container {
            width: 100%;
            height: 85vh;
            background: rgba(0, 0, 0, 0.3);
            border-radius: 15px;
            overflow: hidden;
            position: relative;
            backdrop-filter: blur(10px);
            box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
        }

        #viewer {
            width: 100%;
            height: 100%;
        }

        /* 响应式设计 */
        @media (max-width: 768px) {

            .viewer-container {
                height: 50vh;
            }
        }

    </style>
</head>
<body>
<div class="container">

    <!-- 图片查看界面 -->
    <div class="viewer-interface" >
        <header>
            <h2>图片查看器</h2>
        </header>

        <div class="viewer-container">
            <div id="viewer"></div>
        </div>

    </div>
</div>

<script>


    window.onload = function () {

        const previewUrl = getUrlParam(window.location.href, 'previewUrl');
        initializeViewer(previewUrl);
    }

    function getUrlParam(url, paramName) {
        let queryString = '';
        try {
            const urlObj = new URL(url);
            queryString = urlObj.search;
        } catch (e) {
            // 如果不是标准 URL，但以 ? 开头，当作查询字符串处理
            queryString = url.startsWith('?') ? url : '?' + url;
        }

        const searchParams = new URLSearchParams(queryString);
        let encodedStr = searchParams.get(paramName); // 存在则返回值，否则返回 null
        // 反编码
        const decodedStr = decodeURIComponent(encodedStr);
        console.log(decodedStr); // "Hello World! & 你好"
        return decodedStr; // 存在则返回值，否则返回 null
    }

    // 初始化OpenSeadragon查看器
    function initializeViewer(previewUrl) {
        const viewer = OpenSeadragon({
            id: "viewer",
            prefixUrl: "/images/",
            showNavigationControl: true,
            animationTime: 0.5,
            blendTime: 0.1,
            constrainDuringPan: true,
            maxZoomPixelRatio: 3,
            visibilityRatio: 1,
            zoomPerScroll: 1.5,
            // tileSources: "https://tiffbucket.oss-cn-beijing.aliyuncs.com/tif/my_dzi.dzi"
            tileSources: previewUrl
        });
    }

    // 添加CSS动画
    const style = document.createElement('style');
    style.textContent = `
            @keyframes shake {
                0% { transform: translateX(0); }
                20% { transform: translateX(-10px); }
                40% { transform: translateX(10px); }
                60% { transform: translateX(-10px); }
                80% { transform: translateX(10px); }
                100% { transform: translateX(0); }
            }
        `;
    document.head.appendChild(style);
</script>
</body>
</html>